#include "widget.h"
#include "ui_widget.h"
#include <QDateTimeEdit>

#include "qcustomcalendarwidget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

//    QDateTimeEdit *editor = new QDateTimeEdit(this);
//    editor->setDisplayFormat("yyyy年 MM月 dd日");
//    editor->setCalendarPopup(true);
//    editor->move(100,200);
//    editor->show();



    QDateTimeEdit *dateEdit = new QDateTimeEdit(QDate::currentDate(), this);
    QCustomCalendarWidget* calendarWidget = new QCustomCalendarWidget(this);
    dateEdit->setCalendarPopup(true);  // 日历弹出
    dateEdit->setCalendarWidget(calendarWidget);
    dateEdit->setMinimumDate(QDate::currentDate().addDays(0));  // 0天
    dateEdit->setMaximumDate(QDate::currentDate().addDays(365));  // +365天
    dateEdit->setContextMenuPolicy(Qt::NoContextMenu);
    dateEdit->setFixedSize(150, 26);
    dateEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

    calendarWidget->disconnect(SIGNAL(selectionChanged()));
    calendarWidget->disconnect(SIGNAL(clicked(QDate)));

    connect(calendarWidget, &QCustomCalendarWidget::signalSetCalendarTime, [dateEdit](const QDate& data){
        dateEdit->setDate(data);
    });

    dateEdit->move(100,200);
    dateEdit->show();

}

Widget::~Widget()
{
    delete ui;
}

